<template>
  <div class="sidebar">
    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
      text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-sub-menu :index="item.index" :key="item.index">
            <template #title>
              <el-icon :size="size">
                <component :is="item.icon" />
              </el-icon>
              <span>{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs" :key="subItem.index">
              <el-menu-item :index="subItem.index">
                <el-icon :size="size">
                  <component :is="subItem.icon" />
                </el-icon>
                {{ subItem.title }}
              </el-menu-item>
            </template>
          </el-sub-menu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <el-icon :size="size">
              <component :is="item.icon" />
            </el-icon>
            <template #title>{{ item.title }}</template>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script setup>
import { computed, watch } from "vue";
import { useTagsStore } from "../stores/store.js";
import { useRoute } from "vue-router";

const size = 12;
const items = [
  {
    icon: "HomeFilled",
    index: "/dashboard",
    title: "系统首页",
  },
  {
    icon: "Avatar",
    index: "/userAdmin",
    title: "用户管理",
    subs: [
      {
        icon: 'DocumentCopy',
        index: "/userInfo",
        title: "用户信息",
      },
      {
        icon: "Plus",
        index: "/userAdd",
        title: "用户添加",
      },
    ],
  },
  {
    icon: "CameraFilled",
    index: "/travelAdmin",
    title: "景点管理",
    subs: [
      {
        icon: 'DocumentCopy',
        index: "/travelInfo",
        title: "景点信息",
      },
      {
        icon: "Plus",
        index: "/travelAdd",
        title: "景点添加",
      },
    ],
  },
  // {
  //   icon: "Ticket",
  //   index: "/ticketAdmin",
  //   title: "门票管理",
  //   subs: [
  //     {
  //       icon: 'Tickets',
  //       index: "/ticketInfo",
  //       title: "门票信息",
  //     },
  //     {
  //       icon: "FirstAidKit",
  //       index: "/ticketAdd",
  //       title: "门票添加",
  //     },
  //   ],
  // },
  {
    icon: "List",
    index: "/orderAdmin",
    title: "订单管理",
    subs: [
      {
        icon: 'Postcard',
        index: "/orderInfo",
        title: "订单信息",
      },
      {
        icon:"CirclePlus",
        index:"/orderAdd",
        title: "订单添加",
      }
    ],
  },
  {
    icon: "Management",
    index: "/articleAdmin",
    title: "文章管理",
    subs: [
      {
        icon: 'Document',
        index: "/articleInfo",
        title: "文章信息",
      },
      {
        icon: 'Plus',
        index: "/articleAdd",
        title: "文章添加",
      },
    ],
  },
  // {
  //   icon: "Comment",
  //   index: "commentAdmin",
  //   title: "评论管理",
  //   subs: [
  //     {
  //       icon: 'ChatDotSquare',
  //       index: "/commentInfo",
  //       title: "评论信息",
  //     },
  //     {
  //       icon:"Plus",
  //       index:"/commentAdd",
  //       title: "评论添加",
  //     }
  //   ],
  // },
];
const route = useRoute();
const onRoutes = computed(() => {
  return route.path;
});
const store = useTagsStore();
const collapse = computed(() => {
  return store.collapse;
});
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 200px;
}

.sidebar>ul {
  height: 100%;
}
</style>
